/**
 * ShortestPath.java
 *
 * @author Hagen Boehm
 */


package SSF.OS.OSPFv2;


// ======================== class SSF.OS.OSPFv2.ShortestPath ================================ //
/**
 *  When multiple paths of equal path-type and cost exist to a destination, they are stored in
 *  a single routing table entry. To destinguish between them this class holds the fields that
 *  uniquely indentify a shortest path. Objects of this class are kept in a Vector called
 *  equalCostPaths stored in a routing table entry. Remember, the advRouter field is valid in
 *  case of INTER_AREA routes only!
 */
public class ShortestPath {

  /** The router ID of the router who advertised this path. */
  public int advRouter;

  /** A NextHop Object describing the shortest path stored here. */
  public NextHop nextHop;

  // ----------------------------- constructors ShortestPath --------------------------------- //
  /** Constructs an object that holds the fields which uniquely identifies a shortest path in
   *  case of an inter-area or AS external path.
   *  @param advR The router ID of the router who advertised this path.
   *  @param nH A NextHop describing the path.
   */
  public ShortestPath(int advR, NextHop nH) {
    advRouter = advR;
    nextHop = nH;
  }

  /** Constructs an object that holds the fields which uniquely identifies a shortest path in
   *  any other case.
   *  @param nH A NextHop describing the path.
   */
  public ShortestPath(NextHop nH) {
    advRouter = 0;
    nextHop = nH;
  }

  // ----------------------------- ShortestPath.getViaIntf --------------------------------- //
  /** Return the ip address of the outgoing interface.
   *  @return int value representig ip address of outgoing interface.
   */ 
  public int getViaIntf() {
    return nextHop.viaInterface;
  }

  // ----------------------------- ShortestPath.getNHopIP ---------------------------------- //
  /** Return the ip address of the next hop router if there is one. Otherwise return 0.
   *  @return int value representig ip address of the next hop router if any.
   */ 
  public int getNHopIP() {
    return nextHop.nextHopIPAddr;
  }

  // ------------------------------- ShortestPath.equals ----------------------------------- //
  /** Indicates whether a ShortestPath object is "equal" to this one.
   *  @param sPathObj ShortestPath object to compare.
   *  @return boolean value indicating true if the Objects are equal else indicating false.
   */
  public boolean equals(Object sPathObj) {
    if (!(sPathObj instanceof ShortestPath)) return false;
    ShortestPath sp = (ShortestPath)sPathObj;
    if (!nextHop.equals(sp.nextHop)) {
      return false;
    }
    if (advRouter != sp.advRouter) {
      return false;
    }
    return true;
  }

} // end of class ShortestPath
